const express = require("express");
const tools = require("../../model/tools");
const NavModel = require("../../model/navModel");

var router = express.Router();
router.get("/", async(req, res) => {
    const result = await NavModel.find({})
    if (result.err) {
        console.log(result.err);
    } else {
        console.log(result, '-----11');
    }
    res.send("导航列表")
})
router.get("/add", async(req, res) => {
    const navmodel = new NavModel({
        title: "新闻列表",
        url: 'www.baidu.com'
    })
    const result = await navmodel.save()
    if (result.err) {
        console.log(result.err);
    } else {
        console.log('nav 数据添加成功！');
    }
    res.render("admin/nav/add")
})
router.get("/edit", (req, res) => {
    res.send("修改导航")
})
router.post("/doAdd", tools.multer().single("pic"), (req, res) => {
    //获取表单传过来的数据    
    res.send({
        body: req.body,
        file: req.file
    });
})
router.post("/doEdit", (req, res) => {
    res.send("执行修改")
})

module.exports = router